﻿using DataLayer.Interfaces;
using NHibernate;
using NHibernate.Cfg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataLayer.Implementations
{
    public class NHibernateModel : INHibernateModel
    {
        private ISessionFactory sessionFactory;

        public NHibernateModel()
        {
            Configuration config = new Configuration();
            sessionFactory = config.Configure().BuildSessionFactory();
        }

        public T GetById<T>(int id)
        {
            using (var session = sessionFactory.OpenSession())
            {
                T result = session.Get<T>(id);
                return result;
            }
        }

        public IList<T> GetAll<T>() where T : class
        {
            using (var session = sessionFactory.OpenSession())
            {
                IList<T> result = session.QueryOver<T>().List();
                return result;
            }
        }

        public IList<T> GetByCriterion<T>(NHibernate.Criterion.ICriterion criterion)
        {
            throw new NotImplementedException();
        }
    }
}
